import Vue from 'vue'

const state = {
    messages: [],
    status: null,
    target: "localhost"
}

const getters = {}

const actions = {
    getRecentMessage({state}) {
        state.status = null
        Vue.axios.get(`http://${state.target}:8090/api/recent`).then((result) => {
            if (result.data.length === 0 ) {
                state.status = "没有消息"
            } else {
                state.messages = result.data
            }
        }).catch((err) => {
            console.error("未获取到最近一天的聊天记录", err)
        });
    }
}

const mutations = {}

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}